// 账户与安全
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../tools/tools.dart';

class SafetPage extends StatefulWidget {
  const SafetPage({Key? key}) : super(key: key);

  @override
  State<SafetPage> createState() => _SafetPageState();
}

class _SafetPageState extends State<SafetPage> {
  List<Map<String, dynamic>> listOne = [
    {
      'title': '登录密码',
      'url': '',
    },
    {
      'title': '设置用户名',
      'url': '',
    },
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: SzColor.f4f4f4,
      appBar: buildAppBar(),
      body: Expanded(
        child: CustomScrollView(
          slivers: [
            buildItem(listOne),
          ],
        ),
      ),
    );
  }

// 每项
  SliverList buildItem(List<Map<String, dynamic>> listData) {
    return SliverList(
      delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
        late Map<String, dynamic> data = listData[index];
        return Container(
          margin: EdgeInsets.only(
            top: index > 0 ? rpx(0) : rpx(24),
          ),
          decoration: const BoxDecoration(
            color: Colors.white,
          ),
          child: InkWell(
            onTap: () {
              if (data['url'].length > 0) {
                Get.toNamed(data['url']);
              } else {
                SzEasyLoading.showToast('暂无开启');
              }
            },
            child: Container(
              margin: EdgeInsets.symmetric(horizontal: rpx(40)),
              padding: EdgeInsets.symmetric(vertical: rpx(30)),
              decoration: BoxDecoration(
                border: Border(
                  bottom: BorderSide(
                    width: listData.length - 1 != index ? rpx(2) : 0,
                    color: SzColor.f4f4f4,
                  ),
                ),
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(data['title']),
                  Icon(
                    AliIcon.qingxuanzeyoujiantou,
                    color: const Color(0xffC8C8C8),
                    size: setSp(28),
                  )
                ],
              ),
            ),
          ),
        );
      }, childCount: listData.length),
    );
  }

  AppBar buildAppBar() {
    return AppBar(
      title: const Text(
        '账户与安全',
        style: TextStyle(color: Colors.white),
      ),
      backgroundColor: SzColor.primary,
      centerTitle: true,
      leading: IconButton(
        onPressed: () {
          Get.back();
        },
        icon: Icon(
          Icons.chevron_left,
          color: Colors.white,
          size: setSp(60),
        ),
      ),
    );
  }
}
